<?php
class Main_Model extends CI_Model{
	
	
	function __construct(){
        // Call the Model constructor
        parent::__construct();
    }
		
	function get_produk(){
		$sql="SELECT * from tbl_produk where id_parent='0' order by id_produk asc limit 3";
		//echo $sql;
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->result_array();
		}else{
			return array();
		}
	}
	
	function get_produk_parent($id_parent){
		$sql="SELECT * from tbl_produk where id_parent='".$id_parent."' order by id_produk asc limit 3";
		//echo $sql;
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->result_array();
		}else{
			return array();
		}
	}
	
	function get_news(){
		$sql="SELECT * from tbl_post order by id_post desc limit 3";
		//echo $sql;
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->result_array();
		}else{
			return array();
		}
	}
	
	function get_client(){
		$sql="SELECT * from tbl_client where tampil='ya' order by rand() limit 12";
		//echo $sql;
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->result_array();
		}else{
			return array();
		}
	}
	
	function get_slider(){
		$sql="SELECT * from tbl_slider order by id_slider desc ";
		//echo $sql;
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->result_array();
		}else{
			return array();
		}
	}
	
	function get_portofolio(){
		$sql="SELECT * from tbl_portofolio where jenis = '1' or jenis = '0' order by id_portofolio desc";
		//echo $sql;
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->result_array();
		}else{
			return array();
		}
	}

	function get_portofolio2(){
		$sql="SELECT * from tbl_portofolio where jenis = '1' or jenis = '0' order by id_portofolio desc";
		//echo $sql;
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->result_array();
		}else{
			return array();
		}
	}
	
	function get_products(){
		$sql="SELECT * from tbl_portofolio where jenis = '2' or jenis = '0' order by id_portofolio desc";
		//echo $sql;
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->result_array();
		}else{
			return array();
		}
	}
	
	function get_career_active(){
		$sql="SELECT * FROM tbl_career WHERE DATE_FORMAT(NOW(),'%Y-%m-%d') <= tgl_expired order by id_career desc";
		//echo $sql;
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->result_array();
		}else{
			return array();
		}
	}
	
	function get_detail_page($id){
		$sql="SELECT * from tbl_page where slug='".$id."'";
		//echo $sql;
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->row_array();
		}else{
			return array();
		}
	}
	
	function get_detail_slider($id){
		$sql="SELECT * from tbl_slider where slug='".$id."'";
		//echo $sql;
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->row_array();
		}else{
			return array();
		}
	}
	
	function get_detail_career($id){
		$sql="SELECT * from tbl_career where slug='".$id."'";
		//echo $sql;
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->row_array();
		}else{
			return array();
		}
	}
	
	function get_detail_portofolio($id){
		$sql="SELECT * from tbl_portofolio where slug='".$id."'";
		//echo $sql;
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->row_array();
		}else{
			return array();
		}
	}

	function get_detail_products($id){
		$sql="SELECT * from tbl_portofolio where slug='".$id."'";
		//echo $sql;
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->row_array();
		}else{
			return array();
		}
	}
	
	function get_detail_news($id){
		$sql="SELECT * from tbl_post where slug='".$id."'";
		//echo $sql;
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->row_array();
		}else{
			return array();
		}
	}
	
	function get_detail_produk($id){
		$sql="SELECT * from tbl_produk where slug='".$id."'";
		//echo $sql;
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->row_array();
		}else{
			return array();
		}
	}
	
	//buat client
	function get_all_kategori(){
		$sql="SELECT * from tbl_kategori order by id_kategori desc";
		//echo $sql;
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->result_array();
		}else{
			return array();
		}
	}
	
	function get_client_by_kategori($id){
		$sql="SELECT * from tbl_client where id_kategori='".$id."'";
		//echo $sql;
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->result_array();
		}else{
			return array();
		}
	}

	function magang(){
		$sql="SELECT * from tbl_magang";
		//echo $sql;
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->result_array();
		}else{
			return array();
		}
	}
}
?>